import Vue from 'vue'
import VueRouter from 'vue-router'
import $store from '../store/index'
const Home=() => import(/* webpackChunkName: "home" */  '../views/Home.vue')
const SignIn=() => import(/* webpackChunkName: "sign-in" */  '../views/home/register/SignIn')
const ShowInfo=() => import(/* webpackChunkName: "show-info" */  '../views/home/register/ShowInfo')
const Register=() => import(/* webpackChunkName: "register" */  '../views/home/Register')
const Print=() => import(/* webpackChunkName: "print" */  '../views/Print')

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: Home,
    children:[
      {
        path: '/',
        name: 'home-index',
        components: {
          register:Register
        },
      },
      {
        path: 'sign',
        name: 'home-sign',
        components: {
          register:SignIn
        },
      },
      {
        path: 'info',
        name: 'home-info',
        components: {
          register:ShowInfo
        },
      },
    ]
  },
  {
    path: '/print',
    name: 'print',
    component: Print,
  }
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
});

router.beforeEach((to, from, next) => {
  const loginInfo=$store.getters["getLoginInfo"];
  if(to.name=="home-index"){
    next();
    return;
  }
  if(loginInfo==null){
    next({
      name:"home-index"
    });
    return;
  }
  next();
})

export default router
